function loadMap() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://webapi.amap.com/maps?v=1.3&key=1f47cfba244d5d93a9e615ee660d1284&callback=init";
    document.body.appendChild(script);
}

var latlng = [];
var km = [];

function init() {
    var mapObj = new AMap.Map(mapDiv, {
        view: new AMap.View2D({
            zoom: 15
        })
    });
    for (var i = 0; i < latlng.length; i++) {
        var arr = new Array(); //经纬度坐标数组
        var arrTwo = new Array();
        arrTwo = latlng[i];
        for(var j=0; j< arrTwo.length;j++) {
            arr.push(new AMap.LngLat(arrTwo[j]["lng"], arrTwo[j]["lat"]));
        }
        var polyline = new AMap.Polyline({
            map: mapObj,
            path: arr,
            strokeColor: "#3CB8D9",
            strokeOpacity: 1,
            strokeWeight: 4,
            strokeStyle: "solid",
            strokeDasharray: [10, 5]
        });
    }

    //var arr = new Array(); //经纬度坐标数组
    //for (var i = 0; i < latlng.length; i++) {
    //    arr.push(new AMap.LngLat(latlng[i]["lng"], latlng[i]["lat"]));
    //}
    //
    //var polyline = new AMap.Polyline({
    //    map: mapObj,
    //    path: arr,
    //    strokeColor: "#3CB8D9",
    //    strokeOpacity: 1,
    //    strokeWeight: 4,
    //    strokeStyle: "solid",
    //    strokeDasharray: [10, 5]
    //});

    // start point
    var startMarkerPosition = new AMap.LngLat(latlng[0][0]["lng"], latlng[0][0]["lat"]);
    var startMarker = new AMap.Marker({
        position: startMarkerPosition, //基点位置
        icon: "static/bootstrap/img/cms/icon_start.png", //marker图标，直接传递地址url
        offset: {
            x: -16,
            y: -40
        } //相对于基点的位置
    });
    startMarker.setMap(mapObj);

    // finish point
    $endIndex= latlng.length - 1;
    $childEndIndex = latlng[$endIndex].length-1;
    var finishMarkerPosition = new AMap.LngLat(latlng[$endIndex][$childEndIndex]["lng"], latlng[$endIndex][$childEndIndex]["lat"]);
    var finishMarker = new AMap.Marker({
        position: finishMarkerPosition,
        icon: "static/bootstrap/img/cms/icon_finish.png",
        offset: {
            x: -16,
            y: -40
        }

    });
    finishMarker.setMap(mapObj);

    // kilometer points
    if(km.length)  {
        for (var i = 0; i < km.length; i++) {
        var kmMarkerPosition = new AMap.LngLat(km[i]["lng"], km[i]["lat"]);
        var kmMarker = new AMap.Marker({
            position: kmMarkerPosition,
            icon: "static/bootstrap/img/cms/icon_km.png",
            offset: {
                x: -16,
                y: -16
            },
            content: "<div class=\"map-km-point-div\">" + (i + 1) + "</div>"
        });
        kmMarker.setMap(mapObj);
    }
    }
    //调整视野到合适的位置及级别                 
    mapObj.setFitView();
}
